package dk.pervasivepositioning.project2;

import java.io.IOException;

import android.app.Activity;
import android.location.Location;
import android.location.LocationManager;

public class DistancedBasedStrategy extends ReportingStrategy {

	private Location location = null;
	private int threshold;

	public DistancedBasedStrategy(String URL, LocationManager lm,
			int threshold, Activity activity) throws IOException {
		super(URL);
		this.threshold = threshold;
		this.lm = lm;
		this.activity = activity;
	}

	@Override
	public void receivedLocation(Location loc) throws IOException {
		float[] results = new float[3];
		if (location == null) {
			location = loc;
		}
		Location.distanceBetween(location.getLatitude(),
				location.getLongitude(), loc.getLatitude(), loc.getLongitude(),
				results);
		if (results[0] > threshold) {
			super.sendData(loc);
			location = loc;
		}
	}

	@Override
	public void startup() {
		startUpdates();
	}

	@Override
	public String getStrategy() {
		return "distanced-based"; 
	}
}
